const {secret} = require('../config/config.default')
const jwt = require('jsonwebtoken')
const {promisify} = require('util')
const signAsync = promisify(jwt.sign)
const verifyAsync = promisify(jwt.verify)
const createJWT =async (usertoken)=>{
    const token =await signAsync(usertoken, secret, { expiresIn: "12h" })
    return token
}
/**
 * @description 解析jwt 这个要把他变成一个路由的中间件的形式
 */
const verifyJWT = async (token)=>{
    const userToken = await verifyAsync(token,secret)
    return userToken
}


module.exports = {
    createJWT,
    verifyJWT
}